//
//  LZLocationDistanceView.m
//  laziz_Consumer
//
//  Created by XMac on 16/11/1.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZLocationDistanceView.h"
#import "Masonry.h"


@interface LZLocationDistanceView ()
@property(nonatomic , strong) UILabel *label;
@end

@implementation LZLocationDistanceView

- (instancetype)initWithText:(NSString *)xText
{
    self = [super init];
    if (self) {
        self.backgroundColor = UIColorFromRGB(0xf4f4f4, 1);
        self.layer.cornerRadius = 8;
        self.layer.masksToBounds = YES;
        
        _label = [UILabel new];
        _label.textColor = UIColorFromRGB(0x999999, 1);
        _label.font = [UIFont systemFontOfSize:12];
        _label.text = xText;
        [self addSubview:_label];
        
        [_label makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.equalTo(-8);
            make.centerY.equalTo(0);
        }];
        
        
//        UIImageView *imageView = [[UIImageView alloc]initWithImage:[[UIImage imageNamed:@"location_icon"] imageWithRenderingMode:UIImageRenderingModeAutomatic]];
//        imageView.tintColor = [UIColor whiteColor];
//        [self addSubview:imageView];
//        
//        [imageView makeConstraints:^(MASConstraintMaker *make) {
//            make.trailing.equalTo(_label.leading).offset(-2.5);
//            make.centerY.equalTo(_label.centerY);
//            make.size.equalTo(CGSizeMake(7, 10));
//        }];
    }
    return self;
}

- (void)setDistanceValue:(NSString*)aString {
    self.label.text = aString;
    [self invalidateIntrinsicContentSize];
}

-(CGSize)intrinsicContentSize{
    
    CGSize textSize = [_label intrinsicContentSize];
    
    return CGSizeMake(16+textSize.width, 16);
}


@end
